package fv;

import java.sql.*;

//import com.mysql.jdbc.*;

//import java.

public class mysqlconn {
	static Connection getConn()
	{
		Connection conn = null;
		
		try
		{
			String userName = "root";
			String password = "fashion";
			String url = "jdbc:mysql://localhost:3306/fashionverdict";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(url, userName, password);
			System.out.println("Database connection established");
		}
		catch (Exception e)
		{
			System.err.println("Cannot connect to database server: " + e.getMessage());
		}

		if (conn != null)
			return conn;
		else
			return null;
	}
	
	static void closeConn(Connection conn)
	{
		if (conn != null)
		{
			try 
			{
				conn.close();
				System.out.println("Database connection is closed!");
			}
			catch (Exception e) 
			{
				System.out.println(e.getMessage());
			}
		}
	}
	
/*	public static void main(String[] arg)
	{
		Connection conn = fv.mysqlconn.getConn();
		if (conn != null)
		{
			try
			{
				Statement s = conn.createStatement();
				s.executeQuery("select * from comments");
				ResultSet rs = s.getResultSet();
				while (rs.next())
				{
					System.out.println(rs.getString(1)+"	"+rs.getString(3) +"	" +rs.getString(4)+"	" +rs.getString(5));
				}
				rs.close();
				s.close();
				conn.close();
				System.out.println("Database connection terminated");
			}
			catch (Exception e) 
			{
				System.out.println(e.getMessage());
			}
		}
	}*/
}
